Skip to content

clarify wording of match ergonomics diagnostics (rust_2024_incompatible_pat lint and error) #144006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Jul 16, 2025

Partially addresses #143557:

  • Uses different wording than the Edition Guide chapter, to hopefully stand alone a bit better. Instead of referring to the "default binding mode", it now talks about what can't be written "within elided reference patterns". I ended up going with "elided" instead of "implicit" in hope that it reads bit less like it should behave the same as an explicit reference pattern, but I'm not totally happy with that wording.
  • The explanatory note still points to where the default binding mode was introduced, but only refers to its effect, not what we call it. How that relates to the rest of the diagnostic may still be a bit of a puzzle, but hopefully it isn't too much of one? It also doesn't make sense anymore for the case of & written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about & patterns without further explanation.
  • Links to the stable version of the Edition Guide instead of the nightly version. It looks like almost every link to the Edition Guide in diagnostics is to the nightly version, presumably for the same reason as here: the diagnostics were added before the new Edition was stabilized, then never updated. I'll make a separate PR to clean up the others.

This only changes the diagnostic messages, not the code suggestion or the Edition Guide.

r? @Nadrieril or reassign

@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Nadrieril is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2025
@dianne dianne force-pushed the match-ergonomics-jargon branch from b968622 to 6751630 Compare July 16, 2025 07:13
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Some changes occurred in match checking

cc @Nadrieril

@dianne dianne force-pushed the match-ergonomics-jargon branch from 6751630 to 981b966 Compare July 20, 2025 13:22
Comment on lines -321 to +327
mir_build_rust_2024_incompatible_pat = {$bad_modifiers ->
mir_build_rust_2024_incompatible_pat = explicit {$bad_modifiers ->
*[true] binding modifiers{$bad_ref_pats ->
*[true] {" "}and reference patterns
[false] {""}
}
[false] reference patterns
} may only be written when the default binding mode is `move`{$is_hard_error ->
} may not be written within elided reference patterns{$is_hard_error ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "explicit binding modifiers may not be mixed with automatic reference elision"? Not great either, we might need an official term for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tricky! I'm avoiding "mixed with" since it's only an error when they're nested; that wording would maybe suggest they can't be used in the same pattern at all. An official term could help, but if it doesn't stand on its own we're still relying on users to read and understand the Edition Guide or Reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though my wording will also not be entirely right either for new match ergonomics, since it would be possible to match on inherited references and reset the default binding mode. I'm not really sure how to capture the nuance there in a succinct and self-contained manner. Maybe it needs more subdiagnostic notes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe we can keep "elided reference pattern" if there's a label that points to "a reference was elided here" or sth...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't read that's literally already there x) ok, then we should use the same terminology in both messages:

error: explicit binding modifiers may not be written within elided reference patterns
...
note: matching on a reference type with a non-reference pattern elides the reference

so that users understand the causality between these things. Problem is that this doesn't explain what "eliding a reference" does...

Copy link
Member

@Nadrieril Nadrieril Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we go all-in with the new mental model, this might look like:

error: cannot borrow twice in a pattern
...
note: matching on a reference type with a non-reference pattern makes variables within borrow their targets already

or

error: cannot dereference an implicit borrow
...
note: matching on a reference type with a non-reference pattern causes the contents to be implicitly borrowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants